package qeug.shsh.fi.fromPlugin;

import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.control.events.BeforeItemClickEvent;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.permission.PermissionServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper;

import java.util.EventObject;
import java.util.List;

public class FundAdjustFromPlugin extends AbstractFormPlugin {

    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);
        String userid=RequestContext.get().getUserId();
        long  useridint=Long.valueOf(userid);
        long  mainOrgID=UserServiceHelper.getUserMainOrgId(Long.valueOf(userid));
        DynamicObject userInfo = BusinessDataServiceHelper.loadSingle(useridint,"bos_user", "id,number,name");
        DynamicObject adminInfo = BusinessDataServiceHelper.loadSingle(mainOrgID, "bos_adminorg", "id,number,name");
        this.getModel().setValue("qeug_sqperson", userInfo);//申请人
        this.getModel().setValue("qeug_deparment", adminInfo);//部门


    }

    private final static String qeug_sqperson = "qeug_sqperson";//申请人
    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        String fieldKey = e.getProperty().getName();
        if (StringUtils.equals(qeug_sqperson, fieldKey)) {
            DynamicObject sqpersonInfo = (DynamicObject) this.getModel().getValue("qeug_sqperson");
            if(sqpersonInfo!=null){
                long  useridint=Long.valueOf(sqpersonInfo.get("id").toString());
                long  mainOrgID=UserServiceHelper.getUserMainOrgId(Long.valueOf(useridint));
                DynamicObject adminInfo = BusinessDataServiceHelper.loadSingle(mainOrgID, "bos_adminorg", "id,number,name");
                this.getModel().setValue("qeug_deparment", adminInfo);//部门
            }
        }
    }
}
